<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理
            <small>预约列表管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="findPage1"></el-input>
                <el-button @click="findPage1()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                <el-button type="danger" class="butT" @click="handleDeleteList()">删除</el-button>
            </div>
            <el-table size="small" ref="multipleTable" current-row-key="id" :data="dataList"
                      stripe highlight-current-row @selection-change="handleSelectionChange2">
                <el-table-column type="selection" v-model="orderIds"  width="55"> </el-table-column>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="手机号码" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">确定预约</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">取消预约</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <!--分页查询-->
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <span class="picktime">预约选择日期</span>
                                <el-date-picker
                                        v-model="formData.orderDate"
                                        type="date"
                                        value-format="yyyy-MM-dd"
                                        placeholder="选择日期">
                                </el-date-picker>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="手机号" prop="telephone">
                                    <el-input v-model="formData.telephone"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="姓名" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="身份证号码">
                                    <el-input v-model="formData.idCard"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="性别">
                                    <el-select v-model="formData.sex">
                                        <el-option label="不限" value="0"></el-option>
                                        <el-option label="男" value="1"></el-option>
                                        <el-option label="女" value="2"></el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="年龄">
                                    <el-input v-model="formData.age"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="注意事项">
                                    <el-input v-model="formData.attention" type="textarea"></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <el-table
                                        ref="singleTable"
                                        :data="tableData"
                                        highlight-current-row
                                        @current-change="handleCurrentChange1"
                                        style="width: 100%">
                                    <el-table-column type="index" width="50"></el-table-column>
                                    <el-table-column property="code" label="套餐编码" width="120"></el-table-column>
                                    <el-table-column property="name" label="套餐名" width="120"></el-table-column>
                                    <el-table-column property="remark" label="套餐说明"></el-table-column>
                                </el-table>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="../plugins/healthmobile.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',//添加窗口Tab标签名称
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            orderIds:[], // 复选框id
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            tableData: [],//套餐信息
            currentRow: null,  //单选框当前行
            multipleSelection: [],//复选框
            dialogFormVisible: false,//增加表单是否可见
            rules: {//校验规则
                name: [{required: true, message: '姓名为必填项', trigger: 'blur'}],
                telephone: [{required: true, message: '手机号为必填项', trigger: 'blur'}]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        mounted() {
            this.findPage();
        },
        methods: {
            //对关闭按钮绑定事件
            handleClose() {
                this.cancelHandleEdit();
            },
            //添加
            handleAdd() {
                this.$refs['dataAddForm'].validate((valid) => {
                    if (valid) {
                        //获取用户输入的手机号
                        var telephone = this.formData.telephone;
                        //校验电话号码是否正确
                        if(!checkTelephone(telephone)){
                            //校验不通过，提示错误信息
                            this.$message.error("请输入正确的手机号");
                            return false;
                        }
                        //对用户输入的身份证号进行校验
                        var idCard = this.formData.idCard;
                        if(!checkIdCard(idCard)){
                            //身份证号输入不合法
                            this.$message.error("身份证号码输入错误，请重新输入");
                            return false;
                        }
                        axios.post("/orderSetting/addOrder.do?setmealId="+this.currentRow.id, this.formData).then(
                            (response) => {
                                if (response.data.flag) {
                                    this.$message({
                                        message: response.data.message,
                                        type: 'success'
                                    });
                                } else {
                                    this.$message.error(response.data.message);
                                }
                                this.findPage();
                                this.dialogFormVisible = false;
                            }
                        );
                    } else {
                        this.$message.error("表单验证失败请重新输入");
                    }
                });

            },
            //分页查询
            findPage(row) {
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                axios.get("/orderSetting/findOrdersPage.do", {params: param}).then(
                    (response) => {
                        this.dataList = response.data.data.rows;
                        this.pagination.total = response.data.data.total;
                    }
                );
            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },

            // 弹出添加窗口
            handleCreate() {
                this.activeName = 'first';
                this.dialogFormVisible = true;
                this.resetForm();
                //查询套餐信息
                axios.post("/setmeal/getAllSetmeal.do").then((res)=>{
                    if (res.data.flag){
                        //查询成功
                      this.tableData=res.data.data;
                    }
                })
            },
            // 确定预约,将预约状态改为已预约,再次分页查询
            handleUpdate(row) {
               axios.post("/orderSetting/updateOrderStatus.do",row).then((response)=>{
                   if (response.data.flag) {
                       this.$message({
                           message: response.data.message,
                           type: 'success'
                       });
                       this.findPage1();
                   } else {
                       this.$message.error(response.data.message);
                   }
               })
            },

            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage()
            },

            // 取消预约
            handleDelete(row) {
                if (confirm("您确认要删除吗？")) {
                    axios.post("/orderSetting/delOrder.do",row).then(
                        (response) => {
                            if (response.data.flag) {
                                this.$message({
                                    message: response.data.message,
                                    type: 'success'
                                });
                                this.findPage1();
                            } else {
                                this.$message.error(response.data.message);
                            }
                        }
                    )
                }
            },
            //复选触发事件
            handleSelectionChange2(val) {
                this.multipleSelection = val;
            },
            //单选框触发事件
            handleCurrentChange1(val) {
                this.currentRow = val;
            },
            //批量删除
            handleDeleteList(rows){
                var lists=this.multipleSelection;
                if (confirm("您确认要删除吗？")) {
                    for (const list of lists) {
                        axios.post("/orderSetting/delOrder.do" ,list).then(
                            (response) => {
                                if (response.data.flag) {
                                    this.$message({
                                        message: response.data.message,
                                        type: 'success'
                                    });
                                    this.findPage1();
                                } else {
                                    this.$message.error(response.data.message);
                                }
                            }
                        )
                    }
                }
            },
            findPage1() {
                this.pagination.currentPage = 1;
                this.findPage();
            },
            showMessage(r) {
                if (r == 'Error: Request failed with status code 403') {
                    //权限不足
                    this.$message.error('无访问权限');
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            },
        }
    })
</script>
</html>